package com.mes.basicdata.service;

import java.util.Map;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.data.provider.Page;
import com.mes.basicdata.dao.iface.IDeviceDao;
import com.mes.basicdata.domain.Device;
import com.mes.basicdata.domain.Operation;
import com.mes.common.service.BasicService;

@Service
public class DeviceService extends BasicService<Device> {

	@Autowired
	private IDeviceDao deviceDao;
	
	
	@DataProvider
    public void getDevicesByConditions(Page<Device> page, Map<String, Object> params){
    	if (params != null && !params.equals("") ){
    		try {
    			deviceDao.getDevicesByConditions(page, params);
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}else {
			try {
				//this.getAll(page);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
    }
	
	/**
	 * 根据部门查询设备
	 * @param page
	 * @param deptUid
	 */
	@DataProvider
	public void getDeviceByDept(Page<Device> page, String deptUid){
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Device.class);
		detachedCriteria.add(Restrictions.eq("deptUid", deptUid));
		
		deviceDao.pagingQuery(page, detachedCriteria);
	}
	
}
